import { defineConfig, loadEnv } from 'vite';
import { resolve } from 'path';
import createVitePlugins from './vite/plugins';
// https://vitejs.dev/config/
export default ({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_BASE } = env;
  return defineConfig({
    base: VITE_APP_BASE,
    server: {
      port: 3000,
      proxy: {
        '/api': {
          target: 'http://192.168.10.143:8186',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    resolve: {
      alias: {
        '~': resolve(__dirname, './'),
        '@': resolve(__dirname, './src'),
        'components': resolve(__dirname, './src/components'),
        'styles': resolve(__dirname, './src/styles'),
        'utils': resolve(__dirname, './src/utils')
      }
    },
    build: {
      rollupOptions: {
        // 声明外部依赖项，不会打包
        // external: ['vue'],
        output: {
          globals: {
            vue: 'Vue'
          }
        }
      }
    },
    plugins: createVitePlugins(env, command === 'build')
  });
}
